using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace SiteMapMerging {

public class FrmRegister : Form
{
	private SoftReg softReg = new SoftReg();

	private IContainer components = null;

	private Button btnCreate;

	private TextBox txtRegisterCode;

	private Label label2;

	private TextBox txtMachineCode;

	private Label label1;

	public FrmRegister()
	{
		InitializeComponent();
	}

	private void FrmRegister_Load(object sender, EventArgs e)
	{
		txtMachineCode.Text = softReg.GetMNum();
	}

	private void btnCreate_Click(object sender, EventArgs e)
	{
		try
		{
			if (txtRegisterCode.Text == softReg.GetRNum())
			{
				MessageBox.Show("注册成功！", "信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				string path = Path.Combine(Application.StartupPath, "key.bin");
				File.WriteAllText(path, txtRegisterCode.Text.Trim());
				base.DialogResult = DialogResult.OK;
			}
			else
			{
				MessageBox.Show("注册码错误！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}
		catch (Exception ex)
		{
			throw new Exception(ex.Message);
		}
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.btnCreate = new System.Windows.Forms.Button();
		this.txtRegisterCode = new System.Windows.Forms.TextBox();
		this.label2 = new System.Windows.Forms.Label();
		this.txtMachineCode = new System.Windows.Forms.TextBox();
		this.label1 = new System.Windows.Forms.Label();
		base.SuspendLayout();
		this.btnCreate.Location = new System.Drawing.Point(332, 41);
		this.btnCreate.Name = "btnCreate";
		this.btnCreate.Size = new System.Drawing.Size(75, 48);
		this.btnCreate.TabIndex = 9;
		this.btnCreate.Text = "注册";
		this.btnCreate.UseVisualStyleBackColor = true;
		this.btnCreate.Click += new System.EventHandler(btnCreate_Click);
		this.txtRegisterCode.Location = new System.Drawing.Point(73, 68);
		this.txtRegisterCode.Name = "txtRegisterCode";
		this.txtRegisterCode.Size = new System.Drawing.Size(244, 21);
		this.txtRegisterCode.TabIndex = 8;
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(29, 71);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(41, 12);
		this.label2.TabIndex = 7;
		this.label2.Text = "注册码";
		this.txtMachineCode.BackColor = System.Drawing.Color.White;
		this.txtMachineCode.Location = new System.Drawing.Point(73, 41);
		this.txtMachineCode.Name = "txtMachineCode";
		this.txtMachineCode.ReadOnly = true;
		this.txtMachineCode.Size = new System.Drawing.Size(244, 21);
		this.txtMachineCode.TabIndex = 6;
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(29, 44);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(41, 12);
		this.label1.TabIndex = 5;
		this.label1.Text = "机器码";
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(437, 133);
		base.Controls.Add(this.btnCreate);
		base.Controls.Add(this.txtRegisterCode);
		base.Controls.Add(this.label2);
		base.Controls.Add(this.txtMachineCode);
		base.Controls.Add(this.label1);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
		base.MaximizeBox = false;
		base.Name = "FrmRegister";
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
		this.Text = "软件注册";
		base.Load += new System.EventHandler(FrmRegister_Load);
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
}
